package Thread;

import com.sun.deploy.util.Waiter;

public class Demo3 {
    public static void main(String[] args) {
        Object object = new Object();
        Thread t1 = new Thread(()->{
            System.out.println("t1线程启动");
        });
        Thread t2 = new Thread(()->{
            System.out.println("t2线程启动");
        });
        Thread t3 = new Thread(()->{
            //t3线程加锁,并使用wait等待,唤醒后解锁
            synchronized (object){
                System.out.println("t3线程等待启动");
                try {
                    Thread.sleep(1000);
                }catch(InterruptedException e) {
                    throw new RuntimeException(e);
                }
                try{
                    object.wait();
                }catch(InterruptedException e) {
                    e.printStackTrace();
                }
                for (int i = 0; i < 10; i++) {
                    System.out.println("t3线程启动....");
                }
            }
        });
        Thread t4 = new Thread(()-> {
            try{
                Thread.sleep(1000);
            }catch(InterruptedException e) {
                throw new RuntimeException(e);
            }

            synchronized(object) {
                //t4线程唤醒t3线程的锁
                object.notify();
                System.out.println("t4线程启动");
            }
        });
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
